package com.guigusuqi.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.guigusuqi.app.entity.LoginWxUser;
import com.guigusuqi.app.entity.WxUser;
import com.guigusuqi.app.service.WxUserService;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
@Primary
public class WxUserDetailsServiceImpl implements UserDetailsService
{
    @Resource
    private WxUserService wxUserService;


    @Override
    public UserDetails loadUserByUsername(String openid) throws UsernameNotFoundException
    {
        WxUser user = wxUserService.getUserInfoByOpenId(openid);
        if(Objects.isNull(user))
        {
            throw new RuntimeException("该用户不存在");
        }
        //通过用户id查询权限集合
        //List<String> permsList = sysMenuMapper.selectPermsByUserId(user.getUserId());
        return new LoginWxUser(user);//认证成功之后，把用户信息封装在LoginUser中
    }
}
